//第一种死锁
//一个线程，一把锁，连续加锁两次

class Counter{
    private int count = 0;

    public void add(){
        count++;
    }

    public int get(){
        return count;
    }
}
public class demo01 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for(int i = 0; i < 1000; i++){
                synchronized (counter){
                    synchronized (counter){
                        counter.add();
                    }
                }
            }
        });

        t1.start();
        t1.join();

        System.out.println("count = " + counter.get());
    }
}
//结果：count = 1000
//得益于：java 的 synchronized 引入了可重入的概念